#include "cInput.h"

cInput::cInput(void)
{
	for (int i = 0; i<323; i++)
	{
		m_KeysHeld[i] = false;
	}
}

cInput::~cInput(void) {}

bool cInput::GetEvent()
{
	// Fill the event structure with event information //
	if (SDL_PollEvent(&m_Event))
	{

		// Tell m_KeysHeld that a key has been pressed //
		if (m_Event.type == SDL_KEYDOWN)
		{
			m_KeysHeld[m_Event.key.keysym.sym] = true;
		}
		// Tell m_KeysHeld that a key has been released //
		return true;
	}

	// No event has occured //
	return false;
}

// Return true if user has manually closed the window //
bool cInput::IsQuit()
{
	if (m_Event.type == SDL_QUIT)
		return true;

	return false;
}

// If a key has been pressed, return its SDL key code. Return -1 if no key was pressed. //
int cInput::GetKeyPressed()
{
	if (m_Event.type == SDL_KEYDOWN)
	{
		return m_Event.key.keysym.sym;
	}

	return -1;
}

// Return true if the given key is being held down //
bool cInput::KeyHeld(int key)
{
	return m_KeysHeld[key];
}